
using System;

namespace MxitAPI {
	
	/**
	 * A singleton which stores all details of the current connection to the Mxit server
	 */
	public class Connection {

        public event ConnectionEventHandler LoginEvent;
		
		protected static Connection instance;  /// Singleton instance of this connection class
		public string LoginName { get; set; }  /// The users login name ( phone number )
		public ConnectionType ConnectionType { get; set; } /// Whether this is an Http or Tcp connection
		public ServerInfo PrimaryServer { get; set; }  /// Address information for the primary server
		public ServerInfo BackupServer { get; set; }  /// Information for the backup server
		public ConnectionStatus ConnectionStatus { get; set; }  /// Shows whether the connection is up
		public int PollInterval { get; set; }  /// The interval at which the application polls the Mxit server for new information in seconds
		public string Password { get; set; }  /// The users password
		// TODO Maybe this should be in server info 
		public bool Encrypted { get; set; }  /// Is this session encrpyted 
		// Todo should I leave the property name the same as the class name
		public MessageTransceiver MessageTranceiver { get; set; }  /// Must be used to send messages
		public int LoginDate { get; set; }  /// The unix date in seconds of the last successful login
		public string CurrentUrl { get; set; } /// url returned by mxit at login
		
		protected Connection() {
			ConnectionStatus = ConnectionStatus.Disconnected;
		}
		
		static public Connection Instance {
			get { 
				if ( instance == null )
					instance = new Connection();
				return instance;
			}
		}

        public void DoLoginEvent() {
            if ( LoginEvent != null )
                LoginEvent( this, null );
        }
		
		
	}
}
